require('/utils/Page')

const utils = require('/utils/util')
console.log(utils)
let $request =require('/utils/request')
wx.$request =$request
//全局变量
let $https=require('/utils/request')//全局网络请求变量
wx.$https=$https
wx.baselURL=$https.baselURL
wx.get=$https.get
wx.put=$https.put
wx.post=$https.post
wx.delete=$https.delete


App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        console.log('I am wx login',res)
        // wx.get('http://localhost:8000?/code=' + res.code).then(res =>{
        //   console.log(res)
        wx.get('http://localhost:3000/wxlogin?code=' + res.code).then(res =>{
          // console.log(res)
          wx.userInfo = res
          wx.token = res.token
          if(wx.waitLoginPages.length) {
            for(let i = 0;i < wx.waitLoginPages.length; i ++){
              let page = wx.waitLoginPages[i]
              page.onLoad.call(page.context,page.options)
            }
          }
         })
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    userInfo: null
  }
})